
function Bomb(name) {
    this.name = name;
    this._timer = null;
}

Bomb.prototype.start = function () {
    if (this._timer) {
        clearTimeout(this._timer);
        this._timer = null;
    }
    console.log("%s: 定时器启动，3 秒后爆炸", this.name);
    this._timer = setTimeout(() => {
        this._timer = null;
        console.log("%s: Boom! 💥", this.name);
    }, 3000);
};

Bomb.prototype.clear = function () {
    if (this._timer) {
        clearTimeout(this._timer);
        this._timer = null;
        console.log("%s: 定时器已取消", this.name);
    } else {
        console.log("%s: 没有活动的定时器可取消", this.name);
    }
};

const b1 = new Bomb("b1");
const b2 = new Bomb("b2");


b1.start();
b2.start();

setTimeout(() => {
    b2.clear();
}, 1000);